<template>
    <div>
      <div id="head">
        <van-icon class="biao" size="25px" @click="toHead()" name="arrow-left"
                  style="position: absolute;left: 10px;" />
        能耗预警
      </div>

      <div class="ticket-list">
        <div v-for="one in warningList" :key="one.id" class="ticket-item">
          <div class="ticket-header">
            <div class="ticket-id">{{one.deviceName}}{{one.information}}</div>
            <!--          标签状态右对齐-->
            <div class="ticket-status">
              {{one.createTime}}
            </div>
          </div>
          <div class="ticket-content">
            <div class="ticket-info">
              <div class="ticket-header">设备名称：{{ one.deviceName }}</div>
              <div class="ticket-code">设备编号：{{ one.deviceCode }}</div>
            </div>
            <div class="ticket-actions">
              <van-button type="primary" size="small" v-if="one.status==1" @click="toHandle(one)">待处理</van-button>
              <van-button type="success" size="small" v-if="one.status==2">已处理</van-button>
            </div>
          </div>
        </div>
      </div>
    </div>
</template>

<script>
import axios from "axios";
import { Dialog } from 'vant';

export default {
  data(){
    return{
      warningList:[],
    }
  },
  methods:{
    toHandle(one){
      Dialog.confirm({
        title: '处理',
        message: '确定预警已处理吗？',
      }).then(() => {
            axios.post("http://localhost:9999/warning/updateStatus?id="+one.id).then(res=>{
                this.$toast("处理完成");
                this.findAll();
            })
          })
      .catch(() => {
            // on cancel
        });
    },
    findAll(){
      axios.post("http://localhost:9999/warning/findAll").then(res=>{
        this.warningList = res.data;
      })
    },
    toHead(){
      this.$router.push('/medical')
    }
  },
  created(){
    this.findAll();
  }
}
</script>

<style scoped>
.ticket-status{
  font-size: 12px;
}
#head{
  background-color: #f5f5f5;
  height: 30px;
  width: 100%;
  padding-top: 10px;
  padding-bottom: 10px;
  text-align: center;
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 10px;
}
.ticket-view {
  min-height: 100vh;
  background-color: #f7f8fa;
  padding-top: 46px;
}

.filter-container {
  position: sticky;
  top: 46px;
  z-index: 10;
}

:deep(.van-dropdown-menu) {
  background-color: #fff;
}

.ticket-list {
  padding: 12px;
}

.ticket-item {
  background-color: #fff;
  border-radius: 8px;
  border: #ebedf0 1px solid;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.ticket-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding-bottom: 8px;
  color: #323233;
  border-bottom: 1px solid #ebedf0;
}

.ticket-id {
  font-size: 14px;
  color: red;
}
.ticket-code{
  font-size: 14px;
  color: #323233;
}

.ticket-priority {
  font-size: 14px;
  font-weight: 500;
}

.ticket-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ticket-info {
  font-size: 13px;
  color: #646566;
  line-height: 1.5;
}

:deep(.van-button--primary) {
  background-color: #1989fa;
  border-color: #1989fa;
  color: white;
}

:deep(.van-button--success) {
  background-color: #07c160;
  border-color: #07c160;
  color: white;
}
</style>
